package com.chenjj.scala.bibao



/**
  * 更优雅的结构，Curry
  */
object Curry {
  def inject(array: Array[Int],intial:Int)(operation:(Int,Int)=>Int):Int ={
    var carryOver = intial;

    array.foreach(element => { carryOver = operation(carryOver,element)})

    carryOver
  }

  def main(args: Array[String]): Unit = {
    //对数组求和
    println(inject(Array(1,2,3,4,5),0){(a,b) => {a+b}})
  }
}
